<template>
  <div class="learning-progress-container">
    <!-- 返回按钮 -->
    <div class="back-button-container">
      <el-button 
        type="primary" 
        :icon="ArrowLeft" 
        circle 
        @click="handleBack"
        class="back-button"
        title="返回上一页"
      />
    </div>

    <div class="progress-content">
      <h1 class="progress-title">学习进度</h1>
      
      <div class="progress-layout">
        <!-- 左侧科目选择 -->
        <div class="subject-sidebar">
          <h3 class="sidebar-title">选择科目</h3>
          <div class="subject-list">
            <div 
              v-for="subject in subjects" 
              :key="subject.id"
              class="subject-item"
              :class="{ active: selectedSubject?.id === subject.id }"
              @click="selectSubject(subject)"
            >
              <div class="subject-icon">
                <el-icon :size="24">
                  <component :is="subject.icon" />
                </el-icon>
              </div>
              <div class="subject-info">
                <span class="subject-name">{{ subject.name }}</span>
                <span class="subject-progress">{{ subject.overallProgress }}%</span>
              </div>
            </div>
          </div>
        </div>

        <!-- 右侧进度流程图 -->
        <div class="progress-main">
          <div v-if="selectedSubject" class="progress-detail">
            <div class="subject-header">
              <h2 class="subject-title">{{ selectedSubject.name }}</h2>
              <div class="overall-progress">
                <span class="progress-label">总体进度</span>
                <el-progress 
                  :percentage="selectedSubject.overallProgress" 
                  :color="progressColors"
                  :stroke-width="12"
                  class="progress-bar"
                />
              </div>
            </div>

            <div class="knowledge-flow">
              <h3 class="flow-title">知识点学习流程</h3>
              <div class="flow-container">
                <div 
                  v-for="(knowledge, index) in selectedSubject.knowledgePoints" 
                  :key="knowledge.id"
                  class="knowledge-node"
                  :class="getNodeClass(knowledge.progress)"
                >
                  <div class="node-header">
                    <span class="node-title">{{ knowledge.title }}</span>
                    <span class="node-progress">{{ knowledge.progress }}%</span>
                  </div>
                  <div class="node-progress-bar">
                    <el-progress 
                      :percentage="knowledge.progress" 
                      :color="getProgressColor(knowledge.progress)"
                      :stroke-width="8"
                    />
                  </div>
                  <div class="node-description">{{ knowledge.description }}</div>
                  
                  <!-- 连接线 -->
                  <div 
                    v-if="index < selectedSubject.knowledgePoints.length - 1"
                    class="connection-line"
                    :class="getConnectionClass(knowledge.progress, selectedSubject.knowledgePoints[index + 1].progress)"
                  ></div>
                </div>
              </div>
            </div>
          </div>

          <div v-else class="no-selection">
            <el-empty description="请选择左侧科目查看学习进度" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ArrowLeft, Monitor, Edit, VideoPlay, Brush, Document, Setting, Files, Connection, Lock } from '@element-plus/icons-vue'
import { 
  subjects, 
  selectedSubject, 
  progressColors, 
  handleBack, 
  selectSubject, 
  getNodeClass, 
  getProgressColor, 
  getConnectionClass 
} from './hooks'

// 组件名称
defineOptions({
  name: 'LearningProgressPage'
})

// 页面标题
document.title = '学习进度 - 网络云实验室'
</script>

<style scoped>
.learning-progress-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
  position: relative;
}

.back-button-container {
  position: fixed;
  top: 20px;
  left: 20px;
  z-index: 1000;
}

.back-button {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
  color: white;
  transition: all 0.3s ease;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.back-button:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.back-button:active {
  transform: scale(0.95);
}

.progress-content {
  max-width: 1400px;
  margin: 0 auto;
  padding-top: 60px;
}

.progress-title {
  font-size: 48px;
  font-weight: 700;
  color: white;
  text-align: center;
  margin: 0 0 40px 0;
  text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  letter-spacing: 2px;
}

.progress-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 30px;
  height: calc(100vh - 200px);
}

/* 左侧科目选择 */
.subject-sidebar {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  overflow-y: auto;
}

.sidebar-title {
  font-size: 20px;
  font-weight: 700;
  color: #2c3e50;
  margin: 0 0 20px 0;
  text-align: center;
}

.subject-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.subject-item {
  display: flex;
  align-items: center;
  padding: 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid transparent;
}

.subject-item:hover {
  background: rgba(102, 126, 234, 0.1);
  transform: translateX(5px);
}

.subject-item.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: rgba(255, 255, 255, 0.3);
}

.subject-icon {
  margin-right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(102, 126, 234, 0.1);
}

.subject-item.active .subject-icon {
  background: rgba(255, 255, 255, 0.2);
}

.subject-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.subject-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.subject-progress {
  font-size: 12px;
  opacity: 0.8;
}

/* 右侧进度详情 */
.progress-main {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  padding: 30px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  overflow-y: auto;
}

.subject-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 2px solid #f0f0f0;
}

.subject-title {
  font-size: 28px;
  font-weight: 700;
  color: #2c3e50;
  margin: 0;
}

.overall-progress {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.progress-label {
  font-size: 14px;
  color: #7f8c8d;
  font-weight: 600;
}

.progress-bar {
  width: 200px;
}

/* 知识点流程图 */
.knowledge-flow {
  margin-top: 30px;
}

.flow-title {
  font-size: 20px;
  font-weight: 700;
  color: #2c3e50;
  margin: 0 0 24px 0;
}

.flow-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: relative;
}

.knowledge-node {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 2px solid #e8e8e8;
  transition: all 0.3s ease;
  position: relative;
}

.knowledge-node.completed {
  border-color: #67c23a;
  background: linear-gradient(135deg, #f0f9ff 0%, #e6f7ff 100%);
}

.knowledge-node.in-progress {
  border-color: #409eff;
  background: linear-gradient(135deg, #f0f9ff 0%, #f0f9ff 100%);
}

.knowledge-node.started {
  border-color: #e6a23c;
  background: linear-gradient(135deg, #fffbf0 0%, #fffbf0 100%);
}

.knowledge-node.not-started {
  border-color: #f56c6c;
  background: linear-gradient(135deg, #fff0f0 0%, #fff0f0 100%);
}

.node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.node-title {
  font-size: 16px;
  font-weight: 600;
  color: #2c3e50;
}

.node-progress {
  font-size: 14px;
  font-weight: 600;
  color: #409eff;
}

.node-progress-bar {
  margin-bottom: 12px;
}

.node-description {
  font-size: 14px;
  color: #7f8c8d;
  line-height: 1.5;
}

/* 连接线 */
.connection-line {
  position: absolute;
  left: 50%;
  bottom: -20px;
  width: 2px;
  height: 20px;
  background: #e8e8e8;
  transform: translateX(-50%);
}

.connection-line.completed {
  background: #67c23a;
}

.connection-line.in-progress {
  background: #409eff;
}

.connection-line.not-started {
  background: #f56c6c;
}

/* 空状态 */
.no-selection {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 400px;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .progress-layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .subject-sidebar {
    order: 2;
  }
  
  .progress-main {
    order: 1;
  }
}

@media (max-width: 768px) {
  .progress-title {
    font-size: 36px;
  }
  
  .progress-content {
    padding-top: 40px;
  }
  
  .subject-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .overall-progress {
    align-items: flex-start;
  }
  
  .progress-bar {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .progress-title {
    font-size: 28px;
  }
  
  .subject-title {
    font-size: 24px;
  }
  
  .knowledge-node {
    padding: 16px;
  }
}
</style> 